package org.zjt.auth.security;

import java.util.ArrayList;
import java.util.Collection;

import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserDetailsServiceImple implements UserDetailsService {
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		if( !username.equals("zhang")) throw new UsernameNotFoundException(username + " cannot be found");
		final Collection<SimpleGrantedAuthority> authorities = new ArrayList();
		authorities.add(new SimpleGrantedAuthority("USER"));// 此处设置用户角色为USER,只是为了简单对应起来

		//new org.springframework.security.core.userdetails.User(用户名，加密后的密码)
		return new org.springframework.security.core.userdetails.User("zhang", new EncryptPW().encode("zhang"),authorities);
	}

}